package com.coldfire.nuitinfo11;



import greendroid.app.GDActivity;
import greendroid.widget.ActionBarItem;
import greendroid.widget.ActionBarItem.Type;
import android.content.Intent;

import android.os.Bundle;


import android.widget.TextView;

import com.facebook.android.AsyncFacebookRunner;

import com.facebook.android.Facebook;

import com.facebook.android.R;

import com.coldfire.nuitinfo11.SessionEvents.AuthListener;
import com.coldfire.nuitinfo11.SessionEvents.LogoutListener;

public class MainActivity extends GDActivity {
	
	private final int HOME = -1;	
	private final int SEARSH = 0;
	private final int INFO = 1;
//    private AsyncFacebookRunner mAsyncRunner;
    private LoginButton mLoginButton;
    
    private Facebook mFacebook;
    private AsyncFacebookRunner mAsyncRunner;
    private TextView mText;


	// app id facebook 
    public static final String APP_ID = "271507639567478";

    
   
//    Facebook facebook = new Facebook(APP_ID);
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setActionBarContentView(R.layout.main);
        
        initActionBar();
        
        mLoginButton = (LoginButton) findViewById(R.id.login);
       	mFacebook = new Facebook(APP_ID);
       	mAsyncRunner = new AsyncFacebookRunner(mFacebook);
       	
        mText = (TextView) this.findViewById(R.id.txt);
        
        Tools.initTheToast(this);

        SessionStore.restore(mFacebook, this);
        SessionEvents.addAuthListener(new SampleAuthListener());
        SessionEvents.addLogoutListener(new SampleLogoutListener());
        mLoginButton.init(this, mFacebook, new String[] { "email", "offline_access", "publish_checkins","friends_likes","friends_birthday" ,"friends_about_me","	friends_interests" });

        }
    
    
    @Override
    protected void onActivityResult(int requestCode, int resultCode,
                                    Intent data) {
        mFacebook.authorizeCallback(requestCode, resultCode, data);
    }
    
    
    public class SampleAuthListener implements AuthListener {

        public void onAuthSucceed() {
        	
        	Tools.showTheToast("You have logged in!");
            
            
            Intent intent = new Intent(getApplicationContext(), ListeAmisActivity.class) ;
            startActivity(intent);
//            mRequestButton.setVisibility(View.VISIBLE);
//            mUploadButton.setVisibility(View.VISIBLE);
//            mPostButton.setVisibility(View.VISIBLE);
        }

        public void onAuthFail(String error) {
        	Tools.showTheToast("Login Failed: " + error);
           
        }
    }

    public class SampleLogoutListener implements LogoutListener {
        public void onLogoutBegin() {
        	Tools.showTheToast("Logging out..." );
        }

        public void onLogoutFinish() {
        	Tools.showTheToast("You have logged out!" );
//            mRequestButton.setVisibility(View.INVISIBLE);
//            mUploadButton.setVisibility(View.INVISIBLE);
//            mPostButton.setVisibility(View.INVISIBLE);
        }
    }
    
    private void initActionBar() {
    	addActionBarItem(Type.Help, INFO);
    	addActionBarItem(Type.Search, SEARSH);
    	}
    
    @Override
    public boolean onHandleActionBarItemClick(ActionBarItem item, int position) {
    	switch (item.getItemId()) {
        case INFO:
        	Intent flipIntent = new Intent(this, AboutActivity.class);
        	startActivity(flipIntent);
            break;  
    	case SEARSH:

        	Intent aboutInent = new Intent(this, ListeAmisActivity.class);
        	startActivity(aboutInent);
    		
            break;
     
        default:
            return super.onHandleActionBarItemClick(item, position);
        }
     
        return true;
    }
    
    
    

    
}